package com.tianqu.tms.www.rental.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsDaoException;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.www.rental.actionform.RentalContractAddInputForm;
import com.tianqu.tms.www.rental.viewhelper.RentalContractAddInputViewHelper;
/**
 * 合同查询/修改-中间跳转页面
 * @author mufeiyu
 *
 */
public class RentalContractSearchAddMiddleAction extends TmsAction {
	// 图片添加
	public static String IMAGESADD = "imagesadd";
	// 合同添加
	public static String CONTRACTADD = "contractadd";
	public static String IMG1 = "1";
	public static String IMG2 = "2";
	public static String IMG3 = "3";
	public static String IMG4 = "4";
	public static String IMG5 = "5";
	public static String IMG6 = "6";
	public static String IMG7 = "7";
	public static String IMG8 = "8";
	
	RentalContractAddInputViewHelper viewHelper = new RentalContractAddInputViewHelper();
	private Logger logger = Logger.getLogger(RentalContractAddMiddleAction.class);

	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		RentalContractAddInputForm rentalForm = (RentalContractAddInputForm) form;
		viewHelper = (RentalContractAddInputViewHelper) uc
				.getAttribute(TmsConstants.VIEWHELP);

		viewhel(rentalForm, viewHelper);
		// 判断按钮点击
		if (rentalForm.getBtns1() != null) {
			// 图1
			viewHelper.setButtonType(IMG1);
		} else if (rentalForm.getBtns2() != null) {
			// 图2
			viewHelper.setButtonType(IMG2);
		} else if (rentalForm.getBtns3() != null) {
			// 图3
			viewHelper.setButtonType(IMG3);
		} else if (rentalForm.getBtns4() != null) {
			// 图4
			viewHelper.setButtonType(IMG4);
		} else if (rentalForm.getBtns5() != null) {
			// 图5
			viewHelper.setButtonType(IMG5);
		} else if (rentalForm.getBtns6() != null) {
			// 图6
			viewHelper.setButtonType(IMG6);
		} else if (rentalForm.getBtns7() != null) {
			// 图7
			viewHelper.setButtonType(IMG7);
		} else if (rentalForm.getBtns8() != null) {
			// 图8
			viewHelper.setButtonType(IMG8);
		} else {
			// 保存
			request.setAttribute(TmsConstants.VIEWHELP, viewHelper);
			uc.setAttribute(TmsConstants.VIEWHELP, viewHelper);
			return mapping.findForward(CONTRACTADD);
		}
		logger.debug(this.getClass().getName() + "#execute was completed.");
		request.setAttribute(TmsConstants.VIEWHELP, viewHelper);
		uc.setAttribute(TmsConstants.VIEWHELP, viewHelper);

		return mapping.findForward(IMAGESADD);
	}

	/**
	 * view赋值
	 * 
	 * @param form
	 * @param view
	 * @return
	 */
	private void viewhel(RentalContractAddInputForm form, RentalContractAddInputViewHelper view) throws TmsDaoException{
		//ID
		viewHelper.setId(form.getId());		
		//合同编号
		viewHelper.setSerial(form.getSerial());
		//合同编号保持
		viewHelper.setSerialHold(form.getSerialHold());
		//租金
		viewHelper.setRent(form.getRent());
		//合同开始日期开始区间
		viewHelper.setStartDateS(form.getStartDateS());
		//合同开始日期结束区间
		viewHelper.setStartDateS(form.getStartDateS());
		//合同结束日期开始区间
		viewHelper.setEndDateS(form.getEndDateS());
		//合同结束日期结束区间
		viewHelper.setEndDateE(form.getEndDateE());
		//合同开始日期
		viewHelper.setStartDate(form.getStartDate());
		//合同结束日期
		viewHelper.setEndDate(form.getEndDate());
		//租位编号
		viewHelper.setLocationSerial(form.getLocationSerial());
		//租位编号保持
		viewHelper.setLocationSerialHold(form.getLocationSerialHold());
		//租位类型
		viewHelper.setRentalLocationType(form.getRentalLocationType());
		//租位面积(㎡)
		viewHelper.setAcreage(form.getAcreage());
		//车位数量
		viewHelper.setCarPort(form.getCarPort());
		//合同人姓名
		viewHelper.setOwnerName(form.getOwnerName());
		//身份证号码
		viewHelper.setOwnerIdCardNo(form.getOwnerIdCardNo());
		//性别
		viewHelper.setOwnerSex(form.getOwnerSex());
		//出生日期
		viewHelper.setOwnerBirthday(form.getOwnerBirthday());
		//联系电话
		viewHelper.setOwnerPhone(form.getOwnerPhone());
		//地址	
		viewHelper.setOwnerAddress(form.getOwnerAddress());
		//备注
		viewHelper.setRemark(form.getRemark());
		viewHelper.setPhoto_1(form.getPhoto_1());
		viewHelper.setPhoto_2(form.getPhoto_2());
		viewHelper.setPhoto_3(form.getPhoto_3());
		viewHelper.setPhoto_4(form.getPhoto_4());
		viewHelper.setPhoto_5(form.getPhoto_5());
		viewHelper.setPhoto_6(form.getPhoto_6());
		viewHelper.setPhoto_7(form.getPhoto_7());
		viewHelper.setPhoto_8(form.getPhoto_8());
		//租位编号List
		viewHelper.setLocationSerialList(view.getLocationSerialList());
		//租位ID
		viewHelper.setLocationId(form.getLocationId());
	}
}
